//AC
#include <iostream>
#include <string>
#define ll long long 

using namespace std;

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);

	int n,q;
	cin >> n >> q;
	string s;
	cin >> s;
	string t;
	int a;
	while(q--){
		ll ret = 0;
		cin >> t >> a;
		int i = 0;
		while(i < t.size()){
			ll cnt = 0;	//ll
			while(i < t.size() && t[i] == s[a + i -1]){
				++cnt;
				++i;
			}
			ret += (cnt + 1) * cnt / 2;
			++i;
		}
		cout << ret;
		if(q) cout << endl;
	}	

	return 0;
}

